package Vue;


import Engine.Batiment;
import Engine.Soldat;
import Engine.Unite;
import java.util.ArrayList;
import java.util.List;
import org.newdawn.slick.*;
import org.newdawn.slick.geom.Vector2f;
import org.newdawn.slick.tiled.TiledMap;


public class Lanceur extends BasicGame {




    private TiledMap map;
    private Camera camera;
    private List<Unite> listUnite;
    private List<Batiment> listBatiment;

    private Selection selection;

    public Lanceur() {
        super("Strategy");

    }

    public void init(GameContainer container) throws SlickException {
        map = new TiledMap("./data/tiled/test.tmx","./data/img");
        camera = Camera.getInstance();
        listUnite = new ArrayList<Unite>();
        listBatiment = new ArrayList<Batiment>();
        selection = new Selection(camera,this);
        

        listUnite.add(new Soldat("./data/img/soldat.png",32,192,20.0f));
        listUnite.add(new Soldat("./data/img/soldat.png",52,50,20.0f));



    }

    public void render(GameContainer gc, Graphics g) {

        //La map
        g.scale(camera.getZoom(),camera.getZoom());
        map.render(camera.getPosX(), camera.getPosY());

        //Les unites
        for(Unite unite : listUnite){
            g.resetTransform();
            g.scale(camera.getZoom(),camera.getZoom());
            unite.render(gc, g);
        }

        //Les batiments
        for(Batiment batiment : listBatiment){
            g.resetTransform();
            g.scale(camera.getZoom(),camera.getZoom());
            batiment.render(gc, g);
        }

        //Le rectangle de selection
        selection.render(gc, g);


        //La camara
        g.resetTransform();
        camera.render(gc, g);
    }


    public void update(GameContainer gc, int delta) {
        camera.update(gc, delta);
        selection.update(gc, delta);



    }

    @Override
    public void mousePressed(int button, int x, int y){
        selection.mousePressed(button, x, y);
    }



    @Override
    public void mouseReleased(int button, int x, int y){
        selection.mouseReleased(button, x, y);

    }



    @Override
    public void mouseWheelMoved(int change) {
        //Molette de la souris
        camera.mouseWheelMoved(change);
    }


    @Override
    public void mouseClicked(int button, int x, int y, int clickCount){
        /*if(button == Input.MOUSE_RIGHT_BUTTON && !listEntiteSelected.isEmpty()){
            if(listEntiteSelected.get(0) instanceof Unite){

            }

        }*/
    }

    public List<Batiment> getListBatiment() {
        return listBatiment;
    }

    public List<Unite> getListUnite() {
        return listUnite;
    }




    public static void main(String[] argv) {
            try {
                    AppGameContainer container = new AppGameContainer(new Lanceur());
                    container.setDisplayMode(800,600,false);
                    container.setTargetFrameRate(500);
                    container.start();
            } catch (SlickException e) {
                    e.printStackTrace();
            }
    }
    }


